const ologin = document.querySelector("#login")
const ologinpost = document.querySelector("#loginpost")
const username = document.querySelector("#username")
const password = document.querySelector("#password")

ologin.onclick = () => {
  console.log(username.value, password.value)
  // get 请求
  fetch(`/login?username=${username.value}&password=${password.value}`).then(res => res.text()).then(res => {
    console.log(res)
  })
}
ologinpost.onclick = () => {
  console.log(username.value, password.value)
  // post 请求
  fetch(`/login`,{
    method: "post",
    body: JSON.stringify({
      username: username.value,
      password: password.value
    }),
    headers: {
      "Content-type": "application/json"
    }
  }).then(res => res.json()).then(res => {
    console.log(res)
    if (res.ok === 1) {
      location.href = "/home.html"
    } else {
      console.log("用户名密码不匹配")
      return
    }
  })
}